<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 300px;
            height: 300px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="box"></div>
    <input type="text" id="inp">
    <script>
        function center(e){
            console.log('数据');
            console.log(e);
            console.log(this);
        }
        function jl(fn,time){
            let lastTime = 0
            return function (e){
                let nowTime = Date.now()
                if(nowTime - lastTime < time){
                    return
                }
                lastTime = nowTime
                fn.call(this,e)
            }
        }

        var obt = document.getElementById('box')
        obt.onmousemove = jl(center,300)

        function fd(fn,time){
            let dsq = null
            return function (e){
                clearTimeout(dsq)
              dsq =  setTimeout(() => {
                    fn.call(this,e)
                }, time);
            }
        }
        var inp = document.getElementById('inp')
        inp.onkeydown =fd(center,1000)
        // function center(e){
        //     console.log('数据');
        //     console.log(this);
        //     console.log(e);
        // }

        // function Jl(fn,time){
        //     let lastTime = 0
        //     return function (e){
        //         let nowTime = Date.now()
        //         if(nowTime - lastTime < time){
        //             return
        //         }
        //         lastTime = nowTime
        //         fn.call(this,e)
        //     }
        // }

        // var obx = document.getElementById('box')
        // obx.onmousemove = Jl(center,1000)
        // function center(e){
        //     console.log('数据');
        //     console.log(e);
        //     console.log(this);
        // }

        // function fd (fn,time){
        //     let dsq = null
        //     return function(e){
        //         clearTimeout(dsq)
        //       dsq = setTimeout(() => {
        //             fn.call(this,e)
        //         },time)
        //     }
        // }
        // var inp = document.getElementById('inp')
        // inp.onkeydown = fd(center,1000)
    </script>
</body>
</html>